from src.insertAttendance import insert_single_row_and_get_id
from tools.db_utils import db_operation,execute_single_value_query

SQL_插入学生 = "INSERT INTO student (number, name,gender,clazz_id) VALUES (%(number)s,%(name)s,%(gender)s,%(clazz_id)s)"

def insertStudent(clazz_data,clazz_name):
    clazz_id=execute_single_value_query(f"select id from clazz where name= '{clazz_name}'")
    for row in clazz_data:
        row['number']=row['C']
        row['name'] = row['D']
        row['gender'] = row['E']
        row['clazz_id'] = clazz_id
        insert_single_row_and_get_id(SQL_插入学生,**row)

    return f'SELECT COUNT(*) FROM student where clazz_id={clazz_id}'
